package com.cuit.zuke.admin.controller;

import com.cuit.zuke.admin.pojo.ShowAdmin;
import com.cuit.zuke.admin.pojo.ShowDepartment;
import com.cuit.zuke.admin.service.impl.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class AdminController {
    @Autowired
    private AdminServiceImpl adminService;

    /**
     * 查询管理员列表
     * @param currentPage
     * @param pageSize
     * @return 管理员列表
     */
    @RequestMapping("/queryShowAll")
    public Map<String, Object> queryShow(int currentPage, int pageSize) {
        currentPage = (currentPage-1)*pageSize;
//        System.out.println("hello,admin");
        return adminService.queryShowAll(currentPage,pageSize);
    }

    /**
     * 查询所有部门
     * @return 带有孩子的顶层父部门
     */
    @RequestMapping("/queryDepart")
    public List<ShowDepartment> queryDepart() {
        //        System.out.println(showDepartments);
        return adminService.ShowDepartment();
    }

    /**
     * 根据管理员id查询管理员
     * @param userId
     * @return 单个管理员
     */
    @RequestMapping("/queryAdminById")
    public List<ShowAdmin> queryAdminById(String userId) {
        try {
            Long id = Long.parseLong(userId);
            System.out.println("hello, oneAdmin");
            System.out.println(userId);
            List<ShowAdmin> shows = adminService.queryShowOne(id);
            System.out.println(shows);
            return shows;
        } catch (Exception e) {
            System.out.println("形参类型不匹配");
            return null;
        }
    }

    /**
     * 根据部门id查询管理员列表
     * @param departmentId
     * @param currentPage
     * @param pageSize
     * @return 该部门id对应的部门下的所有员工
     */
    @RequestMapping("/getShowByDepartmentId")
    public Map<String, Object> getShowByDepartmentId(Long departmentId, int currentPage, int pageSize) {
        currentPage = (currentPage-1)*pageSize;
        return adminService.getShowByDepartmentId(departmentId, currentPage, pageSize);
    }

    /**
     * 根据id删除管理员
     * @param userId
     * @return
     */
    @RequestMapping("/deleteAdmin")
    public int deleteAdmin(Long userId) {
        adminService.deleteAdmin(userId);
        return 0;
    }

    /**
     * 批量删除管理员
     * @param userList
     * @return
     */
    @RequestMapping("/multipleDeleted")
    public int multipleDeleted(@RequestBody Long[] userList) {
        for (Long userId : userList) {
            adminService.deleteAdmin(userId);
        }
        return 0;
    }

    public int insertAdmin(ShowAdmin showAdmin) {
        return 0;
    }

    public int updateAdmin(ShowAdmin showAdmin) {
        return 0;
    }

}
